package com.kotlin.lib.coroutines

import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext

fun main() {
    newSingleThreadContext("ctx1").use { ctx1 ->
        newSingleThreadContext("ctx2").use { ctx2 ->

            runBlocking(ctx1) {
                println("${Thread.currentThread().name} start in ctx1 context")

                withContext(ctx2) {
                    println("${Thread.currentThread().name} resume in ctx2 context")
                }
                println("${Thread.currentThread().name}  back to ctx1 context")
            }
        }
    }
}